package lhc.alg.top100;

import java.util.PriorityQueue;

/**
 * description: https://leetcode.cn/problems/kth-largest-element-in-an-array/
 *  我反手就是一个优先级队列 数组中的第K个最大元素
 * author: hongchen.liao
 * date:  2022/9/16
 */
public class _215_ {

    class Solution {
        public int findKthLargest(int[] nums, int k) {
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for(int e : nums){
                pq.offer(e);
                if(pq.size() > k){
                    pq.poll();
                }
            }
            return pq.peek();
        }
    }

}
